class Post < ActiveRecord::Base
  has_and_belongs_to_many :products, :include => [:stores], :uniq => true
  has_and_belongs_to_many :users, :uniq => true
  
  def self.per_page
    1
  end
  
  def user
    users.first.login
  end
  
  def date
    created_at.strftime("%B %d, %Y")
  end
  
  def month
    created_at.strftime("%b")
  end
  
  def day
    created_at.strftime("%d")
  end
  
  def year
    created_at.strftime("%Y")
  end
  
  def stores
    stores = []
    for product in products
      if product.stores.first != nil
        stores << product.stores.first
      end
    end
    return stores.uniq
  end
end
